#include <stdio.h>
#include <dirent.h>
#include <string.h>

int main()
{
// method1:use wayland_display_env
    const char* wayland_display =getenv("WAYLAND_DISPLAY");
    if(wayland_display)
        printf("Wayland Display  is available.\n");
    else
         printf("No Wayland Display is available.\n");


// method2:use drm judge   
    struct dirent*entry;
    DIR *dp = opendir("/sys/class/drm/");
    if(!dp)
    {
        perror("opendir");
        return 1;
    }
    int has_display =0;
    while((entry = readdir(dp)))
    {
        if(strstr(entry->d_name,"card") ||strstr(entry->d_name,"drm"))
        {
            char path[256];
            snprintf(path,sizeof(path),"/sys/class/drm/%s/status",entry->d_name);
            FILE* fp = fopen(path,"r");
            if(fp)
            {
                char status[16];
                if(fscanf(fp,"%15s",status) ==1 && strcmp(status,"connected")==0)
                {
                    has_display =1;
                    printf("-----------------%s:%s\n",entry->d_name,status);
                }
                printf("%s:%s\n",entry->d_name,status);
                fclose(fp);
            }
        }
    }
    closedir(dp);
    if(has_display)
        printf("Display device is connected.\n");
    else
         printf("No Display device is connected.\n");
    return 0;
}